package com.amigo.online.provider.video.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.core.response.StatusCode;
import com.amigo.online.common.core.security.IgnoreSecurity;
import com.amigo.online.provider.video.common.GlobalController;
import com.amigo.online.provider.video.exception.VideoException;
import com.amigo.online.provider.video.service.PromoteService;

@RestController
@RequestMapping(value = "/promote", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class PromoteController extends BaseController {
    @Autowired
    PromoteService promoteService;

    /**
     * 根据金额获取视频预计播放量
     *
     * @param money
     * @return
     */
    @GetMapping("/getExpectedViewAmount/{money}/{type}")
    @IgnoreSecurity
    public ResponseEntity<Response> getExpectedViewAmount(@PathVariable Integer money, @PathVariable Integer type) {
        if (money == null || money < 0) {
            throw new VideoException(StatusCode.BAD_REQUEST);
        }
        return success(promoteService.getExpectedViewAmount(money, type));
    }

    /**
     * 我的速推管理页面
     *
     * @param money
     * @return
     */
    @GetMapping("/getMyPromoteInfo/{page}/{size}")
    public ResponseEntity<Response> getMyPromoteInfo(@PathVariable Integer page, @PathVariable Integer size) {
        page = GlobalController.checkPage(page, size);
        return success(promoteService.getMyPromoteInfo(page, size));
    }

    /**
     * 速推订单详情
     *
     * @param money
     * @return
     */
    @IgnoreSecurity
    @GetMapping("/getPromoteOrderDetail/{promoteOrderId}")
    public ResponseEntity<Response> getPromoteOrderDetail(@PathVariable Long promoteOrderId) {
        return success(promoteService.getPromoteOrderDetail(promoteOrderId));
    }

}
